<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>导出jekyll博客文件</title>
    <script src="./FS.js"></script>
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
    <link rel="icon" href="./favicon.ico" type="image/x-icon">

</head>

<body>
    <div style="text-align:center;">
        <table border="0" align="center">
            <tr>
                <td><h4>标题 * :</h4></td>
                <td><input type="text" id="post_title" name="post_title" style="width:600px"></input></td>
            </tr>
            <tr>
                <td>描述:</td>
                <td><input type="text" id="post_subtitle" name="post_subtitle" style="width:600px"></input></td>
            </tr>
            <tr>
                <td>作者:</td>
                <td><input type="text" id="post_author" name="post_author" style="width:600px"></input></td>
            </tr>
            <tr>
                <td>背景图:</td>
                <td><input type="text" id="post_img" name="post_img" style="width:600px"></input></td>
            </tr>
        </table>

    </div>

    <div style="text-align:center;">
        <h4>标签:</h4>
        <input type="text" id="post_tags1" name="post_tags1" style="width:100px"></input>
        <input type="text" id="post_tags2" name="post_tags2" style="width:100px"></input>
        <input type="text" id="post_tags3" name="post_tags3" style="width:100px"></input>
    </div>

    <div style="text-align:center;">

        <div>
            <h4>
                文章内容:
            </h4>
            <textarea id="post_content" name="post_content" cols="80" rows="12"
                style="OVERFLOW:hidden text-align : center;"></textarea>

        </div>

        日期 : <input type="text" id="mtime" name="mtime" style="width:600px"></input><br />

    </div>


    <hr>
    <div style="text-align:center;">

        <button style="width:120px;height:60px" onclick="downloadMD()">自动导出为md</button>
    </div>

    <footer id="footer">
        <p style="text-align:center;">
            <a href="https://dapenson.xyz/" target="_blank">dapenson.xyz</a><br>
            Dapenson
        </p>
    </footer>

</body>
<script>

    // 导出生成文本函数
    function downloadMD() {

        var m_title = "" + document.getElementById("post_title").value;
        var m_subtitle = "" + document.getElementById("post_subtitle").value;
        var m_author = "" + document.getElementById("post_author").value;
        var m_img = "" + document.getElementById("post_img").value;
        var m_tags1 = "" + document.getElementById("post_tags1").value;
        var m_tags2 = "" + document.getElementById("post_tags2").value;
        var m_tags3 = "" + document.getElementById("post_tags3").value;
        var m_content = "" + document.getElementById("post_content").value;

        //定义当前年月日
        var m_today = document.getElementById("mtime");
        m_today.value = getNowFormatDate();


        if (m_title == null || m_title == "") {
            alert("标题不能为空");
            return;
        }
        if (m_img == null || m_img == "") {
            m_img = "img/post-bg-kuaidi.jpg";
        }

        if (m_author == null || m_author == "") {
            m_author = "Dapenson";
        }

        if (m_subtitle == null || m_subtitle == "") {
            m_subtitle = "  ";
        }
        if (m_tags1 == null || m_tags1 == "") {
            m_tags1 = "  ";
        }
        if (m_tags2 == null || m_tags2 == "") {
            m_tags2 = "  ";
        }
        if (m_tags3 == null || m_tags3 == "") {
            m_tags3 = "  ";
        }

        /*
        ---
        layout:     post
        title:      配置七牛云图床工具
        date:       2020-04-26
        author:     Dapenson
        header-img: img/post-bg-debug.png
        catalog: true
        tags:
            - 图片上传
            - 博客
            - 网站
        ---
        
        */
        var data = "---  \n" +
            "layout:     post\n" +
            "title:      " + m_title + "\n" +
            "subtitle:       " + m_subtitle + "\n" +
            "date:       " + m_today.value + "\n" +
            "author:     " + m_author + "\n" +
            "header-img: " + m_img + "\n" +
            "catalog: true\n" +
            "tags:       \n" +
            "    - " + m_tags1 + "\n" +
            "    - " + m_tags2 + "\n" +
            "    - " + m_tags3 + "\n" +
            "---\n\n" +
            m_content;



        var filename = "" + m_today.value + "-" + m_title + ".md";

        var blob = new Blob([data], { type: "text/plain;charset=utf-8" });
        saveAs(blob, filename);

    }

    // 获取当前年月日
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
</script>

</html>